package eiisan.dao.domain.user;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.lang.Nullable;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * 角色表
 * @table tb_role
 * @date 2019/7/5
 */
@Setter
@Getter
@Entity
@Table(name = "tb_role")
@ApiModel(description = "角色数据")
public class Role implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * 角色ID(不能为空)
	 */
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "id")
	@ApiModelProperty(value = "角色ID")
	private Long id;

	/**
	 * 创建时间(不能为空)
	 */
	@Column(name = "create_time")
	@ApiModelProperty(value = "创建时间")
	private Date createTime;

	/**
	 * 角色名称(不能为空)
	 */
	@Column(name = "name", length = 255)
	@ApiModelProperty(value = "角色名称")
	private String name;

	/**
	 * 角色等级 0-9 0最高,9最低(不能为空,默认值:0)
	 */
	@Column(name = "level")
	@ApiModelProperty(value = "角色等级  0-9  0最高,9最低", example = "0")
	private Byte level = 0;

	/**
	 * 描述
	 */
	@Nullable
	@Column(name = "description", length = 1000)
	@ApiModelProperty(value = "描述")
	private String description;

	/**
	 * 用户数据集合
	 */
	@Nullable
	@OneToMany(mappedBy = "role")
	@OrderBy("id asc")
	private Set<User> users = new HashSet<User>(0);

	/**
	 * 权限数据集合
	 */
	@Nullable
	@ManyToMany(mappedBy = "roles")
	@OrderBy("id asc")
	private Set<Permission> permissions = new HashSet<Permission>(0);

}
